﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UFIDA.U9.CBO.SCM.ProjectTask;
using UFSoft.UBF.Business;

namespace UFIDA.U9.Cust.YYD.PlugBE.MiscRcvTransLP
{
    public class BeforeValidate : UFSoft.UBF.Eventing.IEventSubscriber
    {
        public void Notify(params object[] args)
        {
            #region 从事件参数中取得当前业务实体													 
            if (args == null || args.Length == 0 || !(args[0] is UFSoft.UBF.Business.EntityEvent))
                return;
            BusinessEntity.EntityKey key = ((UFSoft.UBF.Business.EntityEvent)args[0]).EntityKey;
            if (key == null)
                return;
            var holder = key.GetEntity() as UFIDA.U9.InvDoc.MiscRcv.MiscRcvTransL;
            if (holder == null)
                return;
            #endregion
            if (holder.OriginalData.DescFlexSegments.PubDescSeg3 != holder.DescFlexSegments.PubDescSeg3 && !string.IsNullOrEmpty(holder.DescFlexSegments.PubDescSeg3))
            {
                var project = Project.Finder.Find($"Code = '{holder.DescFlexSegments.PubDescSeg3}'");
                if (project != null)
                    holder.BenefitProject = Project.Finder.Find($"Code = '{project.DescFlexField.PubDescSeg1}'");
            }
        }
    }
}
